package logic

import (
	"context"
	"cp/cprpc/cprpc"
	"cp/cprpc/internal/svc"
	"cp/models/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type CourseAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCourseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CourseAddLogic {
	return &CourseAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CourseAddLogic) CourseAdd(in *cprpc.CourseAddRequest) (*cprpc.CourseAddResponse, error) {
	// todo: add your logic here and delete this line
	course := mysql.Course{
		Title:         in.Title,
		TeacherId:     int(in.TeacherId),
		Category:      in.Category,
		Price:         float64(in.Price),
		OriginalPrice: float64(in.OriginalPrice),
		CourseImage:   in.CourseImage,
		Intro:         in.Intro,
		LearnCount:    int(in.LearnCount),
		Status:        in.Status,
	}
	mysql.DB.Debug().Create(&course)

	return &cprpc.CourseAddResponse{
		CourseId: int64(course.ID),
	}, nil
}
